package org.come.action.petpaixu;

import com.tool.btn.MoBanBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import org.come.Jpanel.TestPetJpanel;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.List;

public class PetpxBtn extends MoBanBtn
{
    private TestPetJpanel testPetJpanel;
    private PetpxJpanel petpxJpanel;
    private int p;

    public PetpxBtn(final String iconpath, final int type, final int p, final PetpxJpanel petpxJpanel) {
        super(iconpath, type);
        this.p = p;
        this.petpxJpanel = petpxJpanel;
    }

    public PetpxBtn(final String iconpath, final int type, final int p, final TestPetJpanel testPetJpanel) {
        super(iconpath, type);
        this.p = p;
        this.testPetJpanel = testPetJpanel;
    }

    public PetpxBtn(final String iconpath, final int type, final int p, final String text, final PetpxJpanel petpxJpanel) {
        super(iconpath, type, UIUtils.COLOR_BTNTEXT);
        this.setText(text);
        this.setFont(UIUtils.TEXT_FONT);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.p = p;
        this.petpxJpanel = petpxJpanel;
    }

    public PetpxBtn(final String iconpath, final int type, final int p, final String text, final TestPetJpanel testPetJpanel) {
        super(iconpath, type, UIUtils.COLOR_BTNTEXT);
        this.setText(text);
        this.setFont(UIUtils.TEXT_FONT);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.p = p;
        this.testPetJpanel = testPetJpanel;
    }

    @Override
    public void chooseyes() {
    }

    @Override
    public void chooseno() {
    }

    @Override
    public void nochoose(final MouseEvent e) {
        final int w = (this.testPetJpanel == null) ? this.petpxJpanel.getListpet().getSelectedIndex() : TestPetJpanel.getListpet().getSelectedIndex();
        if (w == -1) {
            return;
        }
        else {
            final RoleData data = RoleData.getRoleData();
            List<String> list = null;
            if (this.p == 0) {
                list = data.PetBb(w, w - 1);
            }
            else {
                if (this.p == 1) {
                    list = data.PetBb(w, w + 1);
                }
                else {
                    if (this.p == 2) {
                        list = data.PetBb(w, 0);
                    }
                    else {
                        list = data.PetBb(w, 99);
                    }
                }
            }
            if (list != null) {
                if (this.testPetJpanel != null) {
                    this.testPetJpanel.init(list);
                }
                else {
                    this.petpxJpanel.init(list);
                    TestPetJpanel.getTestPetJpanel().init(list);
                }
            }
            return;
        }
    }
}
